

<template>
<div>
     <!-- <Button type="primary" @click="modal1 = true">Display dialog box</Button> -->
     <Modal v-model="mode" width="60%"  title="红枣质押-过磅" @change="testChange"  @on-cancel="cancel">
          <Form ref="DlvOrderData"  :model="DlvOrderData"  :rules="ruleInUser" :label-width="100">
                <div style="width:90%;height:auto;margin:0 auto;">
                  <Row>
                     <i-col span="24">
                       <FormItem label="订单编号：" prop="Id">
                          <Input v-model="DlvOrderData.OrderNo" class="orders_disabled" placeholder="请输入用户编号" disabled />
                       </FormItem>
                       <FormItem label="客户名称：" prop="ClassName">
                        <label slot="label">客户名称：</label>
                        <Input v-model="DlvOrderData.CustomerName" class="orders_disabled_custom" placeholder="请输入客户名称"  disabled/>
                     </FormItem> 
                     </i-col>
                    </Row>
                    <Row>
                      <i-col span="8"> 
                        <FormItem label="皮重时间：" prop="SkinWeightTime">
                          <Input v-model="DlvOrderData.SkinWeightTime" class="orders_disabled" placeholder="无皮重时间" style="width:200px;" />
                        </FormItem> 

                        <FormItem label="皮重(公斤)：" prop="SkinWeight">
                          <InputNumber v-model="DlvOrderData.SkinWeight"  class="orders_disabled" style="width:100px;"/>
                        </FormItem>

                        <FormItem label="入厂车牌：" prop="VehicleNo" v-if="DlvOrderData.Status == 2">
                          <Input v-model="DlvOrderData.VehicleNo" class="orders_disabled" placeholder="请输入车牌号" style="width:100px;"/>
                        </FormItem>    

                        <FormItem label="出厂车牌：" prop="OutVehicleNo" v-if="DlvOrderData.Status == 4">
                          <Input v-model="DlvOrderData.OutVehicleNo" class="orders_disabled" placeholder="请输入车牌号" style="width:100px;"/>
                        </FormItem>        
                      </i-col>

                      <i-col span="8">
                        <FormItem label="毛重时间：" prop="RoughWeightTime">
                          <Input v-model="DlvOrderData.RoughWeightTime" class="orders_disabled" placeholder="无毛重时间" style="width:200px;"  disabled/>
                        </FormItem> 

                        <FormItem label="毛重(公斤)：" prop="RoughWeight">
                            <InputNumber v-model="DlvOrderData.RoughWeight" @on-change="weightChange" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;" />
                        </FormItem> 

                        <FormItem label="拉运人员：" prop="Carrier">
                          <Input v-model="DlvOrderData.Carrier" class="orders_disabled" placeholder="请输入拉运人" style="width:100px;" />
                        </FormItem>   
                      </i-col>

                      <i-col span="8">
                        <FormItem label="占空位" prop="">
                          <label slot="label">&nbsp;&nbsp;&nbsp;&nbsp;</label>
                        </FormItem> 

                        <FormItem label="净重(公斤)：" prop="NetWeight">
                          <InputNumber v-model="DlvOrderData.NetWeight" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;"  disabled/>
                        </FormItem> 

                        <FormItem label="拉运电话：" prop="CarrierTelephone">
                          <Input v-model="DlvOrderData.CarrierTelephone" class="orders_disabled" placeholder="请输入电话号码" style="width:100px;" />
                        </FormItem>    
                      </i-col>
                    </Row>

                    <Row>
                      <i-col span="24">
                        <FormItem>
                          <Button type="primary" :loading="loading" class="buttn_rough" v-if="DlvOrderData.Status==2" @click="handleSubmit('DlvOrderData',3)">称皮重</Button>
                          <Button type="warning" :loading="loading" class="buttn_skin" v-if="DlvOrderData.Status==4" @click="handleSubmit('DlvOrderData',5)">称毛重</Button>
                          <!-- <Button @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button> -->
                        </FormItem>
                      </i-col>
                   </Row>

                </div>
              </Form>


        <div slot="footer" >
            <!-- <Button type="error" size="large" long :loading="modal_loading" @click="del">Delete</Button> -->
        </div>
    </Modal>
</div>
</template>

<script>
import {getCompanyList,getDeptList,updateDlvOrderData,timestampToDate} from "@/api/data";
import { formatDate } from '../../components/date.js';
import { getToken } from "@/libs/util";
export default {
    name: 'Edit',
    data () {
        return {
          loading:false,
          mode:this.edit,
          
          //表单验证规则
          ruleInUser: {

            VehicleNo: [
              { required: true, message: '请填写车牌号码', trigger: 'blur' },
              { pattern: /(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$)/, message: '请输入正确的车牌号', trigger: 'blur' }
            ],
           
           OutVehicleNo: [
              { required: true, message: '请填写车牌号码', trigger: 'blur' },
              { pattern: /(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$)/, message: '请输入正确的车牌号', trigger: 'blur' }
            ],
            

            CarrierTelephone: [
              { required: true, message: '请输入拉运人手机号码', trigger: 'blur' },
              { pattern: /^1(3|4|5|6|7|8|9)\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
            ],


          },
         
          listdata:[]

        };
    },
    props:{
        edit:{
            type:Boolean ,
            required:true
        },
        DlvOrderData:{
            type:Object,
            required:true 
        },
        


    },
    methods: {
      weightChange(){
        var skinWeight = this.DlvOrderData.SkinWeight
        var roughWeight = this.DlvOrderData.RoughWeight
        var stat = this.DlvOrderData.Status
        if(stat == 4){
          this.DlvOrderData.NetWeight = roughWeight -skinWeight
        }
      },
      testChange(val){
        this.$emit('testChange',val);
       },
      cancel(){
           this.loading = false; 
          let data = {
            mode:false
          }
          this.$emit('cancelCallBack', data);
       },
      //提交编辑后的userInfo
      handleSubmit(name,status) {
        
        this.$refs[name].validate(valid => { 
          console.log("提交验证：",valid)    
          if (valid) {  
            this.loading = true;      
            this.submit(status);
          } else {
            this.$Message.error("请填写相关信息!");
          }
        });
      },
    submit(status){
        var skinWeightTime = this.DlvOrderData.SkinWeightTime
        var roughWeightTime = this.DlvOrderData.RoughWeightTime
        var roughWeightPerson = this.DlvOrderData.RoughWeightPerson
        var skinWeightPerson = this.DlvOrderData.SkinWeightPerson
        
        if(status == 3){
          //出厂---皮重时间
          skinWeightTime = timestampToDate(new Date(),'yyyy-MM-dd HH:mm:ss')
          skinWeightPerson = getToken()
        }else if(status == 6){
          //毛重时间
          roughWeightTime = timestampToDate(new Date(),'yyyy-MM-dd HH:mm:ss')
          roughWeightPerson = getToken()
        }

        const data = {
            Id:this.DlvOrderData.Id,
            Carrier:this.DlvOrderData.Carrier,
            CarrierTelephone:this.DlvOrderData.CarrierTelephone,
            VehicleNo:this.DlvOrderData.VehicleNo,
            RoughWeightPerson:roughWeightPerson,
            RoughWeightTime:roughWeightTime,
            RoughWeight:this.DlvOrderData.RoughWeight,
            SkinWeightPerson:skinWeightPerson,
            SkinWeightTime:skinWeightTime,
            SkinWeight:this.DlvOrderData.SkinWeight,
            NetWeight:this.DlvOrderData.NetWeight,
            Status:status
    };

    var submitStatus = true
      if(status == 5 && this.DlvOrderData.VehicleNo != this.DlvOrderData.OutVehicleNo){
         submitStatus = false
         this.loading = false
         this.$Message.error("出厂和入厂车牌不一致！");
      }
      if(this.DlvOrderData.NetWeight < 0){
         submitStatus = false
         this.loading = false
         this.$Message.error("皮重大于毛重，请检查！");
      }

      //判断是否符合提交条件
      if(submitStatus){
        updateDlvOrderData(data).then(res =>{
            if(res == "OK"){
              this.$Message.success("提交成功");
              this.loading = false; 
              let data = {
                mode:false
              }
              this.$emit('success', data);   
            }else if(response.data.flag == 0){
            this.$Message.success("提交失败"); 
            }else if(response.data.flag == 2){
            this.$Message.success("状态过期");
            }
        }).catch(error => {
            this.$Message.error("请核对之后重新提交1");
             this.loading = false; 
       });
      }
      


     },
    },
    mounted () {
      const cmpdata = {
        fields:"Id,CompanyName",
        offset:"0",
        limit:"-1"
      };
      const dptdata = {
        fields:"Id,DeptName",
        offset:"0",
        limit:"-1"
      };
      //获得包含公司Id和companyname字段的全部列表
      // getCompanyList(cmpdata).then(res =>{
      //   this.CompanyList = res.List;
        
      // });
      //获得包含公司Id和companyname字段的全部列表
      // getDeptList(dptdata).then(res =>{
      //   this.DeptList = res.List;
      // });
    },
    watch: {
        edit(val) {
        this.mode = val
    }
}
}
</script>
<style>
.dept .ivu-select-placeholder{
color:#515a6e!important;
}

.orders_disabled_custom input{
    border:none;
    background-color:#fff!important;
    color:gray!important;
    width: 280px;
}

.buttn_rough{
  width: 100px;
}

.buttn_skin{
  width: 100px;
  margin-left: 150px;
}
</style>